import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:mokeng/routes/app_pages.dart';
import 'package:mokeng/utils/utils.dart';
import 'package:mokeng/values/colors.dart';
import 'package:mokeng/widgets/widgets.dart';

class MineView extends GetView {
  const MineView({super.key});

  /// 头部
  Widget _topBar() {
    return Container(
      margin: EdgeInsets.only(top: 44.0.h), // 顶部系统栏 44px
      padding: EdgeInsets.symmetric(horizontal: 20.0.w),
      child: Row(children: [
        Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text(
              '我的'.tr,
              style: TextStyle(
                // fontFamily: 'Avenir',
                fontWeight: FontWeight.bold,
                color: AppColors.primaryText,
                fontSize: 24.sp,
                height: 1,
              ),
            ),
            Container(
              width: 15.w,
              height: 5.h,
              margin: EdgeInsets.only(top: 5.h),
              decoration: BoxDecoration(
                  color: Colors.red, borderRadius: 5.radius),
            )
          ],
        ),
        const Spacer(),
        InkWell(
          onTap: () {},
          child: Container(
              width: 36.w,
              height: 36.w,
              decoration: const BoxDecoration(
                shape: BoxShape.circle,
                color: Colors.white,
              ),
              child: Image.asset(
                "assets/images/mine_ic_service.webp",
                width: 24.w,
                height: 24.w,
              )),
        ),
      ]),
    );
  }

  /// 登陆信息栏
  Widget _loginCard() {
    return Container(
      margin: EdgeInsets.only(top: 16.h, left: 16.w, right: 16.w),
      height: 164.h,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(8.w)),
        // boxShadow: [
        //   BoxShadow(
        //       color: Colors.black.withOpacity(0.05),
        //       offset: const Offset(0, 3),
        //       blurRadius: 5,
        //       spreadRadius: 1)
        // ]
      ),
      child: Column(
        children: [
          Container(
            height: 98.h,
            padding: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 8.w),
            child: Row(
              children: [
                netImageCached(
                  "https://oss.mokeng.com/image/2024-01-0516-04-53196868-IMG_0006.jpg",
                  width: 50.w,
                  height: 50.w,
                ),
                16.vGap,
                Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      children: [
                        Text(
                          "灶门祢豆子",
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            color: AppColors.primaryText,
                            fontSize: 18.sp,
                            height: 1,
                          ),
                        ),
                        Image.asset(
                          "assets/images/mine_ic_buy.webp",
                          width: 20.w,
                          height: 20.w,
                        ),
                        Image.asset(
                          "assets/images/mine_ic_buy.webp",
                          width: 20.w,
                          height: 20.w,
                        ),
                      ],
                    ),
                    Divider(
                      height: 5.h,
                    ),
                    Row(
                      children: [
                        Container(
                          width: 36.w,
                          height: 18.w,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            color: AppColors.borderColor,
                            borderRadius:
                                BorderRadius.all(Radius.circular(9.w)),
                          ),
                          child: Text(
                            "Lv.1",
                            textAlign: TextAlign.center,
                            style: TextStyle(
                              color: AppColors.primaryText,
                              fontSize: 9.sp,
                              fontFamily: "YouSheBiaoTiHei",
                            ),
                          ),
                        )
                      ],
                    )
                  ],
                ),
                const Spacer(),
                Icon(
                  Icons.arrow_forward_ios,
                  size: 15.w,
                  color: AppColors.tabBarElement,
                )
              ],
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              btnImageTextWidget(
                onTap: () {
                  // Get.toNamed(AppRoutes.Mine);
                },
                imagePath: "assets/images/mine_ic_buy.webp",
                title: "买入".tr,
              ),
              btnImageTextWidget(
                onTap: () {
                  // Get.toNamed(AppRoutes.Mine);
                },
                imagePath: "assets/images/mine_ic_sale.webp",
                title: "卖出".tr,
              ),
              btnImageTextWidget(
                onTap: () {
                  // Get.toNamed(AppRoutes.Mine);
                },
                imagePath: "assets/images/mine_ic_box.webp",
                title: "盒柜".tr,
              ),
              btnImageTextWidget(
                onTap: () {
                  // Get.toNamed(AppRoutes.Mine);
                },
                imagePath: "assets/images/mine_ic_card_bag.webp",
                title: "卡包".tr,
              ),
            ],
          )
        ],
      ),
    );
  }

  Widget _mineItemContainer(List<Widget> children) {
    return Container(
      margin: EdgeInsets.only(top: 16.h, left: 16.w, right: 16.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(8.w)),
      ),
      child: Column(
        children: children,
      ),
    );
  }

  Widget _mineItem(
      {required String icon, required String name, GestureTapCallback? onTap}) {
    return InkWell(
      onTap: onTap,
      child: Container(
        height: 56.h,
        padding: EdgeInsets.symmetric(horizontal: 16.w),
        child: Row(
          children: [
            Image.asset(icon, width: 22.w, height: 22.w),
            16.vGap,
            Text(
              name,
              style: TextStyle(
                fontSize: 16.sp,
                color: AppColors.primaryText,
                fontWeight: FontWeight.w500,
              ),
            ),
            const Spacer(),
            Icon(
              Icons.arrow_forward_ios,
              size: 15.w,
              color: AppColors.tabBarElement,
            )
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        _topBar(),
        Expanded(
          child: ListView(
            padding: EdgeInsets.only(top: 0, bottom: 60.h),
            children: [
              _loginCard(),
              _mineItemContainer([
                _mineItem(
                    icon: "assets/images/mine_ic_create.webp", name: "求购".tr),
                _mineItem(
                    icon: "assets/images/mine_ic_create.webp", name: "代理收益".tr),
              ]),
              _mineItemContainer([
                _mineItem(
                    icon: "assets/images/mine_ic_create.webp", name: "钱包".tr),
              ]),
              _mineItemContainer([
                _mineItem(
                  icon: "assets/images/mine_ic_create.webp",
                  name: "设置".tr,
                  onTap: () => Get.toNamed(Routes.Setting),
                ),
              ]),
            ],
          ),
        ),
      ],
    );
  }
}
